<?php
	require_once APPPATH.'controllers/gnc_mng'.EXT;

	class Bud_pu extends Gnc_mng {
		protected $model_path = 'bud/m_pu';
		protected $detail_model_path = 'bud/m_kpu';
		
		public function process_add() {
			$add_data = NULL;
			
			$this->validate_add();
			$this->process_add_input($add_data);
			$this->process_add_process($add_data);
			$this->process_add_output($add_data);
		}

		protected function validate_add(){
			if(!ereg('[0-9]{1}[.][0-9]{2}',$_POST['key'])){
				$this->common->flash_message('Penamaan key salah, sesuaikan dng format 0.00', IMPORTANT);
				redirect($this->referrer);
			} 
			if(strpos($_POST['key'],$_POST['key_bud_m_kpu']) != 0){
				$this->common->flash_message('Key tidak sesuai dengan key induk', IMPORTANT);
				redirect($this->referrer);
			} 
		}

		protected function view_output(&$view_data = NULL) {
			if (is_null($view_data)) $view_data = array();
		
			//required: $mode
			if (isset($view_data['mode'])) {
				$mode = $view_data['mode'];
			
				$application        = get_application($this);
				$application_title    = $this->common->get_application_description($application);
				$unit                = get_unit($this);
				$unit_title            = $this->common->get_unit_description($unit);
				$unit_controller    = get_unit_controller($this);
				$page                 = $this->view_attr[$mode]['title'];
				
				$metadata = compact('application', 'application_title', 'unit', 'unit_title', 'unit_controller', 'page');

				if (isset($view_data['content_data']['data']['master']['data']['current'])) {
					$view_data['nav_data']['master_record'] = $view_data['content_data']['data']['master']['data']['current'];
				}
				
				$nav_data             = array_merge($metadata, $view_data['nav_data']);
				$content_data        = array_merge($metadata, $view_data['content_data']);
							
				$navigation            = $this->load->view('bud/navigation/administrator/navigation', '', true).$this->load->view('bud/navigation/administrator/nav_minor',array('url'=>'pu'), true);
				$content            = $this->load->view($this->view_attr[$mode]['content'], $content_data, TRUE);
			
				$data = array_merge($metadata, compact('navigation', 'content'));

				$this->load->view($this->view_attr[$mode]['layout'], $data);
			}
		}

		function add_output(&$add_data = NULL) {
			if (is_null($add_data)) $add_data = array();
		
			//required: $mode
			if (isset($add_data['mode'])) {
				$mode = $add_data['mode'];
		
				$application        = get_application($this);
				$application_title    = $this->common->get_application_description($application);
				$unit                = get_unit($this);
				$unit_title            = $this->common->get_unit_description($unit);
				$unit_controller    = get_unit_controller($this);
				$page                 = $this->add_attr[$mode]['title'];
				
				$metadata = compact('application', 'application_title', 'unit', 'unit_title', 'unit_controller', 'page');

				$nav_data             = array_merge($metadata, $add_data['nav_data']);
				$content_data        = array_merge($metadata, $add_data['content_data']);
				
				$navigation         = $this->load->view('bud/navigation/administrator/navigation', '', true).$this->load->view('bud/navigation/administrator/nav_minor',array('url'=>'pu'), true);
				
				$content            = $this->load->view($this->add_attr[$mode]['content'], $content_data, TRUE);
			
				$data = array_merge($metadata, compact('navigation', 'content'));

				$this->load->view($this->add_attr[$mode]['layout'], $data);
			}
		}

		protected function update_output(&$update_data = NULL) {
			if (is_null($update_data)) $update_data = array();
		
			//required: $mode
			if (isset($update_data['mode'])) {
				$mode = $update_data['mode'];
		
				$application		= get_application($this);
				$application_title	= $this->common->get_application_description($application);
				$unit				= get_unit($this);
				$unit_title			= $this->common->get_unit_description($unit);
				$unit_controller	= get_unit_controller($this);
				$page 				= $this->update_attr[$mode]['title'];
				
				$metadata = compact('application', 'application_title', 'unit', 'unit_title', 'unit_controller', 'page');

				$nav_data 			= array_merge($metadata, $update_data['nav_data']);
				$content_data		= array_merge($metadata, $update_data['content_data']);
				
				$navigation			= $this->load->view('bud/navigation/administrator/navigation', '', true).$this->load->view('bud/navigation/administrator/nav_minor',array('url'=>'pu'), true);
				$content			= $this->load->view($this->update_attr[$mode]['content'], $content_data, TRUE);;
			
				$data = array_merge($metadata, compact('navigation', 'content'));

				$this->load->view($this->update_attr[$mode]['layout'], $data);
			}
		}
	}
?>